package pluginUtils;

/** Pour le moment, uniquement les rotations par rapport aux axes **/
public class Rotation3D {
	private double coef[][]=new double[3][3]; 
	private double theAngle;
	private char direction; 
	
	public Rotation3D(char dir,double angle){
		theAngle=angle; 
		direction=dir; 
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++) coef[i][j]=0; 
		switch(dir){
		case 'x': coef[0][0]=1; 
				  coef[1][1]=Math.cos(angle); 
				  coef[2][2]=Math.cos(angle); 
				  coef[1][2]=-Math.sin(angle); 
				  coef[2][1]=Math.sin(angle); 
				  break; 
		case 'y': coef[1][1]=1; 
		  coef[0][0]=Math.cos(angle); 
		  coef[2][2]=Math.cos(angle); 
		  coef[0][2]=Math.sin(angle); 
		  coef[2][0]=-Math.sin(angle); 
		  break; 	
		case 'z': coef[2][2]=1; 
		  coef[0][0]=Math.cos(angle); 
		  coef[1][1]=Math.cos(angle); 
		  coef[0][1]=-Math.sin(angle); 
		  coef[1][0]=Math.sin(angle); 
		  break; 	
		}  		  
	}
	
	public double getTheAngle() {
		return theAngle;
	}

	public char getDirection() {
		return direction;
	}

	public Pos3D rotate(Pos3D A){
		double x=this.coef[0][0]*A.x+this.coef[0][1]*A.y+this.coef[0][2]*A.z; 
		double y=this.coef[1][0]*A.x+this.coef[1][1]*A.y+this.coef[1][2]*A.z; 
		double z=this.coef[2][0]*A.x+this.coef[2][1]*A.y+this.coef[2][2]*A.z;
		return new Pos3D(x,y,z);
	}
}


